home *** CD-ROM | disk | FTP | other *** search
- Path: FreeNet.Carleton.CA!aq436
- From: aq436@FreeNet.Carleton.CA (Jerry Boyd)
- Newsgroups: comp.lang.c
- Subject: Compare Function
- Date: 11 Apr 1996 23:46:07 GMT
- Organization: The National Capital FreeNet
- Sender: aq436@freenet2.carleton.ca (Jerry Boyd)
- Message-ID: <4kk5jv$41o@freenet-news.carleton.ca>
- Reply-To: aq436@FreeNet.Carleton.CA (Jerry Boyd)
- NNTP-Posting-Host: freenet2.carleton.ca
-
-
-
-
- How would I write a compare function (compare_strings, for
- instance) that uses character pointers. I need something
- that would take a string and compare it to a list, or dictionary,
- of other words. If the word is in the dictionary, the
- definition would be printed. If the word is not in the dictionary,
- it would say something like, sorry, that word isn't in the dict.
-
-
- This is how the compare_strings function should look, but need to
- implement using pointers.
-
- int compare_strings (char s1[], char s2[])
- {
- int i = 0, answer
-
- while ( s1[i] == s2[i] && s1[i] != '\0' && s2[i] != '\0' )
- ++i;
-
- if ( s1[i] < s2[i] )
- answer = -1;
- else if ( s1[i] == s2[i] )
- answer = 0;
- else
- answer = 1; /* s1 > s2 */
-
- return (answer);
- }
-
-
-
- The dictionary will look something like this, and will tie
- in with the rest of the program.
-
- {{ "cobol", "common busuness oriented language" },
- { "fortran", "formula translator" },
- { "John Doe", "God of programming" }}
-
-
- --
-
-